using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Labirinto_Magico
{
    public class Input
    {
        public bool leftMousePressed;
        public Vector2 mousePosition;
    }

    public class InputHandler : Microsoft.Xna.Framework.GameComponent
    {
        public Input mInput;
        GraphicsDeviceManager mGraphics;
        ButtonState mMouseStateBefore = ButtonState.Released;

        public InputHandler(Game game, GraphicsDeviceManager gd)
            : base(game)
        {
            mInput = new Input();
            mInput.leftMousePressed = false;
            mInput.mousePosition = Vector2.Zero;
            mGraphics = gd;
            Game.Services.AddService(typeof(Input), mInput);
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime iTime)
        {
            if (mMouseStateBefore == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Released)
                mInput.leftMousePressed = true;
            else
                mInput.leftMousePressed = false;

            mInput.mousePosition.X = Mouse.GetState().X;
            mInput.mousePosition.Y = Mouse.GetState().Y;

            mMouseStateBefore = Mouse.GetState().LeftButton;

            base.Update(iTime);
        }
    }
}
